#ifndef EVENTLOOP_EVENTLOOPPROXY_H
#define EVENTLOOP_EVENTLOPPPROXY_H

#include "IOchannelProxyFwd.h"
#include "utility/Noncopyable.h"

#include <memory>

class Eventloop;
class Poller;

class EventloopProxy final {
public:
    static constexpr int POLL_TIMEOUT_MS = 5000;

    explicit EventloopProxy(Eventloop &loop);
    ~EventloopProxy();

    Eventloop &eventloop() const { return _loop; }

    void poll_event();

    bool has(const IOchannelProxy &channel) const;
    void remove(IOchannelProxy &channel) const;
    void update(IOchannelProxy &channel) const;

private:
    NONCOPYABLE(EventloopProxy);

    IOchannelProxyRefs _activeChannels;
    OptionalIOchannelProxyRef _currentActiveChannel;
    const std::unique_ptr<Poller> _poller;
    Eventloop &_loop;
    bool _handlingEvent;
};

inline bool operator==(const EventloopProxy &lhs, const EventloopProxy &rhs) {
    return &lhs == &rhs;
}


#endif